﻿using System;
using Microsoft.ComplexEventProcessing;
using Microsoft.ComplexEventProcessing.Adapters;

namespace $Namespace$
{

    /// <summary>
    /// Factory to instantiate a text file writer output adapter.
    /// </summary>
    public sealed class $FactoryClassName$ : IOutputAdapterFactory<$ConfigClassName$>
    {
        /// <summary>
        /// Returns an instance of an output adapter.
        /// </summary>
        /// <param name="configInfo">Configuration passed from the query binding.</param>
        /// <param name="eventShape">Event shape requested from the query binding.</param>
        /// <param name="cepEventType">Event type produced by the bound query template.</param>
        /// <returns>An instance of a text file writer output adapter.</returns>
        public OutputAdapterBase Create($ConfigClassName$ configInfo, EventShape eventShape, CepEventType cepEventType)
        {
            //TODO: Determine if you need anything more sophisticated in the Create.
            //This may include logic to reuse already created adapters.
            OutputAdapterBase adapter = default(OutputAdapterBase);

            switch (eventShape)
            {
                case EventShape.Edge:
                    adapter = new $EdgeClassName$(configInfo, cepEventType);
                    break;
                case EventShape.Interval:
                    adapter = new $IntervalClassName$(configInfo, cepEventType);
                    break; 
                case EventShape.Point:
                    adapter = new $PointClassName$(configInfo, cepEventType);
                    break; 
                default:                    
                    throw new ArgumentException(string.Format(
                        System.Globalization.CultureInfo.InvariantCulture,
                        "$FactoryClassName$ cannot instantiate adapter with event shape {0}",
                        eventShape.ToString()));
            }

            return adapter;
        }

        /// <summary>
        /// Dispose method.
        /// </summary>
        public void Dispose()
        {
            this.Dispose(true); 
            GC.SuppressFinalize(this);
        }

        /// <summary>
        /// Releases unmanaged and - optionally - managed resources
        /// </summary>
        /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
        private void Dispose(bool disposing)
        {
            
        }

        /// <summary>
        /// Releases unmanaged resources and performs other cleanup operations before the
        /// <see cref="UntypedOutputAdapterFactory"/> is reclaimed by garbage collection.
        /// </summary>
        ~$FactoryClassName$()
        {
            this.Dispose(false);
        }
    }
}
